<?php

namespace app\aiv110\controller;

use app\aiv110\controller\CommonController;
use think\Validate;
use think\Db;
use app\util\Utils;
use app\util\QyWx;

class YuyueController extends CommonController {
    /*
     * code列表
     */

    public function code() {
        /*
         * 0  成功
         * 1  参数错误
         * 2  验证失败
         * 150000  
         * 150001  
         * 150002  
         * 150003
         * 150004
         */
    }

    /*
     * 待接单超过五分钟
     * author xfwed 
     * date 2021.07.21
     */

    public function timeOutOrder() {
        $list = Db::name('yuyue')
                ->where('status', 2)
                ->where('user_confirm_time', '<', date('Y-m-d H:i:s',time()-300))
                ->where('start_time','<',date('Y-m-d H:i:s'))
                ->field('count(id) num,staff_id')
                ->group('staff_id')
                ->select();
//        print_r($list);die;
        foreach ($list as $k => $v){
            $num = $v['num'];
            $staff_id = $v['staff_id'];
            $a = Db::name('staff')->where('id',$staff_id)->value('qy_wechat');
            if($num > 0){
                $sms = new QyWx();
                $result = $sms->sendSMS($a,'【紧急】您当前有'.$num.'个预约订单未接单，为不影响客户体验，请尽快接单！');
            }
        }
        return Utils::ajaxReturn(0, 'success', null);
    }
    
    /*
     * APP推送完给企业微信也推送一下
     * java调佣
     * author xfwed 
     * date 2021.09.08
     */

    public function QyWxMessage() {
        $qy_wechat = input('param.qy_wechat');
        $content = input('param.content');
        $sms = new QyWx();
        $result = $sms->sendSMS($qy_wechat,$content);
        
        return Utils::ajaxReturn(0, 'success', $result);
    }
}
